import React from 'react'
import TabooModel from "../../../model/taboo";
import Admin from "../../../layout/Admin";
import {Form, Input, Button,} from "antd";
import Info from "../../../service/info";

class Taboo extends React.Component {

    constructor(props) {
        super(props)
        this.model = new TabooModel()
        this.state = {
            word: '',
        }
    }

    check = () => {
        this.model
            .check({msg: [this.state.word]})
            .then(resp => {
                const code = resp.data.code
                if (code === 0) {
                    Info.success(`${this.state.word}不是敏感词`)
                }
            })
    }

    delete = () => {
        const word = this.state.word
        this.model
            .delete({msg: word,})
            .then(resp => {
                const code = resp.data.code
                if (code === 0) {
                    Info.success(`已经成功删除 ${word} 敏感词`)
                    this.setState({
                        word: '',
                    })
                }
            })
    }

    add = () => {
        const word = this.state.word
        this.model
            .add({msg: word,})
            .then(resp => {
                const code = resp.data.code
                if (code === 0) {
                    Info.success(`已经成功添加 ${word} 敏感词`)
                    this.setState({
                        word: '',
                    })
                }
            })
    }


    render() {
        return <Admin>
            <div className='list-container'>
                <Input
                    placeholder='输入敏感词查询/删除/添加'
                    value={this.state.word}
                    onChange={e => this.setState({word: e.target.value,})}
                />
                <div style={{marginTop: '16px',}}>
                    <Button onClick={this.check}>查询</Button>
                    <Button onClick={this.delete}>删除</Button>
                    <Button onClick={this.add}>添加</Button>
                </div>
            </div>
        </Admin>
    }
}

export default Taboo